function solverfile2matparam(solverfile)
% Solver = 'E:\Academic\X\!FROcclusion\2017-01-15-ResSR\code\VDSR20sidual_solver.prototxt';

if nargin == 0 || isempty(solverfile)
    ParamList = clipboard('paste');
else
    ParamList = fileread(solverfile);
end

%%
% ParamList = strsplit(ParamList, '\n');
ParamList = regexp(ParamList, '\n', 'split');

% [c, matches] = regexp(ParamList, '\n', 'split', 'match');

ParamList = cellfun(@FormatRep, ParamList, 'uniformoutput', false);

ParamList = [sprintf('%s\n\n', 'clear solv'), ParamList{:}];
clipboard('copy', ParamList);
return

%%
% fid = fopen(solverfile);
% tline = fgetl(fid);
% while ischar(tline)
%     ParamList = sprintf('%s%s\n', ParamList, FormatRep(tline));
%     tline = fgetl(fid);
% end
% 
% fclose(fid);
% clipboard('copy', ParamList);

%%
function ParamLine = FormatRep(ParamLine)

ParamLine = strtrim(ParamLine);
if isempty(ParamLine)
    ParamLine = sprintf('\n');
    return
end

% ParamLine = 'base_lr: 0.1  # the origin is 0.01';
ExpList = {
    '"', ''''
    '^#\s*', '% '
    '\s*#\s*', '; % '
    '\s*:\s*', ' = '
    '(([a-z]|[A-Z])\w+ = )', 'solv.$0'
    'CPU', '''CPU'''
    'GPU', '''GPU'''
    };

% str = '#net: "examples/My_Decon/VDSR20sidual.prototxt"';
% if ParamLine(1) == '#'
%     ParamLine = ['% ', strtrim(ParamLine(2:end))];
% end

for i = 1 : size(ExpList, 1)
    ParamLine = regexprep(ParamLine, ExpList{i, 1}, ExpList{i, 2});
end
ParamLine = sprintf('%s;\n', ParamLine);
